import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/Home.vue'

Vue.use(VueRouter)
//获取原型对象上的push函数
const originalPush = VueRouter.prototype.push
//修改原型对象中的push方法
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}

  const routes = [
  {
    path: '',
    rediect: '/Home',
    component: Home
  },
  {
    path: '/Home',
    name: 'Home',
    component: Home
  },
  {
    path: '/Cate',
    name: 'Cate',
    component: () => import('../views/Cate.vue')
  },
  {
    path: '/ClassDetails/:id/:name',
    name: 'ClassDetails',
    component: () => import('../views/ClassDetails.vue')
  },
  {
    path: '/BookDetails/:id',
    name: 'BookDetails',
    component: () => import('../views/BookDetails.vue')
  },
  {
    path: '/Search',
    name: 'Search',
    component: () => import('../views/Search.vue')
  },
  {
    path: '/RankList/:type/:size',
    name: 'RankList',
    component: () => import('../views/RankList.vue')
  },
  {
    path: '/BookCatalog/:id',
    name: 'BookCatalog',
    component: () => import('../views/BookCatalog.vue')
  },
  {
    path: '/BookRead/:id/:label',
    name: 'BookRead',
    component: () => import('../views/BookRead.vue')
  }
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes,
  scrollBehavior(to, from, savedPosition) {
    return {x:0,y:0}
  }
})

export default router
